package org.phoenixframework.api.search.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.phoenixframework.common.tools.ResultModel;

import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 *
 * @author doublelifeke
 * Email: hautxxxyzjk@163.com
 * DateTime: 2020/12/22 22:22
 * Description:
 */
public class BaseController {

    protected ResultModel<?> buildByPage(Page page) {
        HashMap<String, Object> result = new HashMap<>(8);
        result.put("items", page.getRecords());
        result.put("total", page.getTotal());
        return ResultModel.ok(result);
    }

    protected ResultModel<?> buildByList(Object objects) {
        HashMap<String, Object> result = new HashMap<>(8);
        result.put("items", objects);
        return ResultModel.ok(result);
    }

    protected ResultModel<?> buildByBool(Boolean result) {
        return result ? ResultModel.ok() : ResultModel.error();
    }

    protected ResultModel<?> buildByObject(Object object) {
        HashMap<String, Object> result = new HashMap<>(8);
        result.put("item", object);
        return ResultModel.ok(result);
    }

}
